package com.nuctech.hardwaredriver.serialport_library.core;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by 心魂free on 2019/10/30.
 * <p>
 * 等待唤醒管理
 */

public class WaitSignalManager {

    private Lock lock = new ReentrantLock();
    private Condition readCondition;
    private Condition writeCondition;

    private WaitSignalManager() {

        readCondition = lock.newCondition();
        writeCondition = lock.newCondition();
    }

    private static class SingletonHolder {

        private static final WaitSignalManager INSTANCE = new WaitSignalManager();

    }

    public static WaitSignalManager getInstance() {

        return SingletonHolder.INSTANCE;
    }

    public Lock getLock() {
        return lock;
    }

    public Condition getReadCondition() {
        return readCondition;
    }

    public Condition getWriteCondition() {
        return writeCondition;
    }
}
